package org.jaaksi.test.handler;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

/**
 * Created by Fcy on 2015/10/2.<br/>
 * 模拟 猎豹清理的检测垃圾动画
 */
public class NumbAnimator extends Activity implements Runnable {

    private Button button;
    private Handler mhandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0) {
                button.setText(String.valueOf(msg.arg1));
//                sendEmptyMessageDelayed(0, 10);
            }
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_numb_animator);
        button = (Button) findViewById(R.id.btn_num);
    }

    public void start(View view) {
        new Thread(this).start();
    }

    // 模拟耗时操作
    @Override
    public void run() {
        long i = 0;
        // 模拟 猎豹清理的检测垃圾动画
        while (true) {
            i += 1;
            Message msg = mhandler.obtainMessage(0);
            msg.arg1 = (int) i;
            mhandler.sendMessageDelayed(msg, 100);
        }
    }
}